<?php
namespace app\admin\controller;

use think\Controller;

class User extends Controller
{
    public function initialize()
    {
        parent::initialize();
    }


    public function login()
    {
        if (is_login()) {
            $this->redirect('admin/index/index');
        }

        if (request()->isPost()) {
            $account = input('post.account', '', 'text');
            $password = input('post.password', '', 'text');
            $userModel = model('User');
            $uid = $userModel->login($account, $password);
            if ($uid > 0) {
                $userModel->doLogin($uid);
                $this->success('登录成功', url('admin/index/index'), '', 1.5);
            } else {
                $this->error('登录失败');
            }
        } else {
            return view('login');
        }
    }

    public function logout()
    {
        model('User')->doLogout();
        $this->redirect('admin/user/login');
    }


}
